package uniqueMorseRepresentations;


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
//
//public class Solution {
//    public int uniqueMorseRepresentations(String[] words) {
//        String []mos = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
//        Map<Character,String> map = new HashMap<>();
//        for (int i = 0; i < mos.length; i++) {
//            map.put((char) ('a'+i),mos[i]);
//        }
//        Set<String> set = new HashSet<>();
//        for (int i = 0; i < words.length; i++) {
//            StringBuilder sb = new StringBuilder();
//            for (int j = 0; j < words[i].length(); j++) {
//                sb.append(map.get(words[i].charAt(j)));
//            }
//            set.add(sb.toString());
//        }
//        return set.size();
//    }
//}
class Solution {
    public static final String[] MORSE = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
            "....", "..", ".---", "-.-", ".-..", "--", "-.",
            "---", ".--.", "--.-", ".-.", "...", "-", "..-",
            "...-", ".--", "-..-", "-.--", "--.."};

    public int uniqueMorseRepresentations(String[] words) {
        Set<String> seen = new HashSet<String>();
        for (String word : words) {
            StringBuilder code = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                char c = word.charAt(i);
                code.append(MORSE[c - 'a']);
            }
            seen.add(code.toString());
        }
        return seen.size();
    }
}
